//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MBUnitOfMeasure.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Math/Rounding.h>
#include <gen/QL/Experimental/Commodities/UnitOfMeasure.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure () : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
    try
    {
#ifdef HANDLE
        _phMBUnitOfMeasure = NULL;
#endif
        _ppMBUnitOfMeasure = new boost::shared_ptr<QuantLib::MBUnitOfMeasure> (new QuantLib::MBUnitOfMeasure ( ));
        SetUnitOfMeasure (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (boost::shared_ptr<QuantLib::MBUnitOfMeasure>& childNative, Object^ owner) : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
#ifdef HANDLE
	_phMBUnitOfMeasure = NULL;
#endif
	_ppMBUnitOfMeasure = &childNative;
    _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
}
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (QuantLib::MBUnitOfMeasure& childNative, Object^ owner) : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
#ifdef HANDLE
	_phMBUnitOfMeasure = NULL;
#endif
	_ppMBUnitOfMeasure = new boost::shared_ptr<QuantLib::MBUnitOfMeasure> (&childNative);
    _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
    _MBUnitOfMeasureOwner = owner;
    _UnitOfMeasureOwner = owner;
}

Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (CMBUnitOfMeasure^ copy) : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
#ifdef HANDLE
	_phMBUnitOfMeasure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMBUnitOfMeasure = new boost::shared_ptr<QuantLib::MBUnitOfMeasure> (copy->GetShared());
        _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
    }
}
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (System::Type^ t) : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
#ifdef HANDLE
	_phMBUnitOfMeasure = NULL;
#endif
	if (!t->IsSubclassOf(CMBUnitOfMeasure::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (QuantLib::Handle<QuantLib::MBUnitOfMeasure>& childNative, Object^ owner)  : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
	_phMBUnitOfMeasure = &childNative;
	_ppMBUnitOfMeasure = &static_cast<boost::shared_ptr<QuantLib::MBUnitOfMeasure>>(childNative.currentLink());
    _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
    _MBUnitOfMeasureOwner = owner;
}
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (QuantLib::Handle<QuantLib::MBUnitOfMeasure> childNative)  : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
	_phMBUnitOfMeasure = &childNative;
	_ppMBUnitOfMeasure = &static_cast<boost::shared_ptr<QuantLib::MBUnitOfMeasure>>(childNative.currentLink());
    _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::CMBUnitOfMeasure (QuantLib::MBUnitOfMeasure childNative)  : CUnitOfMeasure(CMBUnitOfMeasure::typeid)
{
#ifdef HANDLE
	_phMBUnitOfMeasure = NULL;
#endif
	_ppMBUnitOfMeasure = new boost::shared_ptr<QuantLib::MBUnitOfMeasure> (new QuantLib::MBUnitOfMeasure (childNative));
    _ppUnitOfMeasure = new boost::shared_ptr<QuantLib::UnitOfMeasure> (boost::dynamic_pointer_cast<QuantLib::UnitOfMeasure> (*_ppMBUnitOfMeasure));
}
#endif

Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::~CMBUnitOfMeasure ()
{
    if (_ppMBUnitOfMeasure != NULL)
    {
	    delete _ppMBUnitOfMeasure;
        _ppMBUnitOfMeasure = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::!CMBUnitOfMeasure ()
{
    if (_ppMBUnitOfMeasure != NULL)
    {
	    delete _ppMBUnitOfMeasure;
    }
}
QuantLib::MBUnitOfMeasure& Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::GetReference ()
{
    if (_ppMBUnitOfMeasure == NULL) throw gcnew NativeNullException ();
	return **_ppMBUnitOfMeasure;
}
boost::shared_ptr<QuantLib::MBUnitOfMeasure>& Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::GetShared ()
{
    if (_ppMBUnitOfMeasure == NULL) throw gcnew NativeNullException ();
	return *_ppMBUnitOfMeasure;
}
QuantLib::MBUnitOfMeasure* Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::GetPointer ()
{
    if (_ppMBUnitOfMeasure == NULL) throw gcnew NativeNullException ();
	return &**_ppMBUnitOfMeasure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MBUnitOfMeasure>& Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::GetHandle ()
{
	if (_phMBUnitOfMeasure == NULL)
	{
		_phMBUnitOfMeasure = new Handle<QuantLib::MBUnitOfMeasure> (*_ppMBUnitOfMeasure);
	}
	return *_phMBUnitOfMeasure;
}
#endif
bool Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure::HasNative () 
{
	return (_ppMBUnitOfMeasure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Commodities::IMBUnitOfMeasure^ Cephei::QL::Experimental::Commodities::CMBUnitOfMeasure_Factory::Create ()
{
    return gcnew CMBUnitOfMeasure ();
}
